package com.hmall.search.controller;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParam;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 搜索栏自动补全功能
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestions(String key) {
        return searchService.getSuggestions(key);
    }

    /**
     * 过滤项聚合功能
     */
    @PostMapping("/filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParam params) {
        return searchService.getFilters(params);
    }


    /**
     * 实现基本搜索功能
     * - 关键字搜索
     * - 分类、品牌、价格过滤
     * - 排序
     * - 分页
     * - 高亮
     * - 竞价排名
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> search(@RequestBody RequestParam params) {
        return searchService.search(params);
    }




























}
